//
//  AlertsDetailController.m
//  gdemm
//
//  Created by 乔明超 on 16/5/19.
//  Copyright © 2016年 Goldencis. All rights reserved.
//

#import "AlertsDetailController.h"
#import "Masonry.h"
@interface AlertsDetailController ()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *senderLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;

@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UIView *lineView;

@end

@implementation AlertsDetailController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    //判断是否打开了水印策略，添加水印效果
    if ([[UserDefaultsUtil shareInstance] getBool:LC_OPENWATERMARKPOLICY]) {
        for (int i = 0; i < 3; i++) {
            UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(20, i * (WINDOWHEIGHT - 200)/2, 250, 80)];
            label.font = [UIFont systemFontOfSize:16];
            label.textColor = [UIColor grayColor];
            label.transform = CGAffineTransformMakeRotation(-M_1_PI);
            label.text =  [[UserDefaultsUtil shareInstance]getString:LC_WATRMARKTEXT];
            [self.view addSubview:label];
        }
    }
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeSystem];
    if ([DeviceTypeJudge isPadDeviceType]) {
        leftButton.frame = CGRectMake(0, 0, 20, 20);
    }else{
        leftButton.frame = CGRectMake(0, 0, 16, 16);
    }
    
    [leftButton setImage:[[UIImage imageNamed:@"navigationBar_back"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [leftButton addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc]initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    self.navigationItem.title = NSLocalizedString(@"str_detail",  @"详情");
    //设置数据
    self.titleLabel.text    = self.messageInfo.noticeTitle;
    self.senderLabel.text   = self.messageInfo.accountName;
    self.timeLabel.text     = [self getTime:self.messageInfo.noticeTime];
    self.contentLabel.text  = self.messageInfo.noticeCon;
    if (![DeviceTypeJudge isPadDeviceType]){
    
        _titleLabel.font = [UIFont systemFontOfSize:17];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.view.mas_top).offset(26);
            make.left.mas_equalTo(7);
        }];
        
        _senderLabel.font = [UIFont systemFontOfSize:11];
        [_senderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_titleLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(7);
        }];
        
        _timeLabel.font = [UIFont systemFontOfSize:11];
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(_senderLabel);
             make.left.mas_equalTo(_senderLabel.mas_right).offset(25);
        }];
        
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_senderLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(7);
            make.right.mas_equalTo(-7);
        }];
        
        _contentLabel.font = [UIFont systemFontOfSize:14];
        [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_lineView.mas_bottom).offset(20);
            make.left.mas_equalTo(10);
            make.right.mas_equalTo(-10);
        }];
    }
  
}

-(NSString * )getTime:(NSString *) date{
    NSDateFormatter * dateFormat = [[NSDateFormatter alloc]init];
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    [dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
    NSDate *showDate =[dateFormat dateFromString:date];
    NSCalendar * calendar = [NSCalendar currentCalendar];
    NSDateComponents * components =  [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:showDate toDate:[NSDate date] options:NSCalendarWrapComponents];
    if (components.year) {
        [dateFormat setDateFormat:@"MM-dd HH:mm"];
    }else{
        if (components.month) {
            [dateFormat setDateFormat:@"MM-dd HH:mm"];
        }else{
            [dateFormat setDateFormat:@"HH:mm"];
        }
    }
    
    return [dateFormat stringFromDate:showDate];
}


@end
